# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: site-packages\sqlalchemy\dialects\mssql\zxjdbc.py
"""
.. dialect:: mssql+zxjdbc
    :name: zxJDBC for Jython
    :dbapi: zxjdbc
    :connectstring: mssql+zxjdbc://user:pass@host:port/dbname[?key=value&key=value...]
    :driverurl: http://jtds.sourceforge.net/

    .. note:: Jython is not supported by current versions of SQLAlchemy.  The
       zxjdbc dialect should be considered as experimental.

"""
from ...connectors.zxJDBC import ZxJDBCConnector
from .base import MSDialect, MSExecutionContext
from ... import engine


class MSExecutionContext_zxjdbc(MSExecutionContext):
    _embedded_scope_identity = False

    def pre_exec(self):
        super(MSExecutionContext_zxjdbc, self).pre_exec()
        if self._select_lastrowid:
            if self.dialect.use_scope_identity:
                self._embedded_scope_identity = True
                self.statement += "; SELECT scope_identity()"

    def post_exec(self):
        if self._embedded_scope_identity:
            while True:
                try:
                    row = self.cursor.fetchall()[0]
                    break
                except self.dialect.dbapi.Error:
                    self.cursor.nextset()

            self._lastrowid = int(row[0])
        if self.isinsert or self.isupdate or self.isdelete:
            if self.compiled.returning:
                self._result_proxy = engine.FullyBufferedResultProxy(self)
        if self._enable_identity_insert:
            table = self.dialect.identifier_preparer.format_table(
                self.compiled.statement.table
            )
            self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table)


class MSDialect_zxjdbc(ZxJDBCConnector, MSDialect):
    jdbc_db_name = "jtds:sqlserver"
    jdbc_driver_name = "net.sourceforge.jtds.jdbc.Driver"
    execution_ctx_cls = MSExecutionContext_zxjdbc

    def _get_server_version_info(self, connection):
        return tuple((int(x) for x in connection.connection.dbversion.split(".")))


dialect = MSDialect_zxjdbc
